<?php
namespace App\Transformers;

//use App\Models\Permission;
use Spatie\Permission\Models\Permission;
use League\Fractal\TransformerAbstract;

class PermissionTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['children'];

    public function transform(Permission $permission)
    {
        return [
            'id' => $permission->id,
            'name' => $permission->name,
            'parent_id'=> $permission->parent_id,
            'alias' => $permission->alias,
        ];
    }

    public function includeChildren(Permission $permission)
    {
        $transformer = new self();
        $transformer->setDefaultIncludes(['children']);
        return $this->collection($permission->children, $transformer);
    }
}